const hasPermission = {
    install(Vue, options) {
        Vue.directive('has', {
            inserted: (el, binding, vnode) => {
                //console.time()
                filterGlobalPermission(el, binding, vnode);
                //console.timeEnd() //计时结束并输出时长
            }
        });
    }
};

/**
 * 全局权限控制
 */
export function filterGlobalPermission(el, binding, vnode) {
    let UserInfo = JSON.parse(localStorage.getItem("userinfo") || "[]");
    //用户 权限
    let permissionList = UserInfo.permissions || [];
    // let allPermissionList = [];

    //设置全局配置是否有命中
    let invalidFlag = false; //无效命中
    if (permissionList != null && permissionList != "" && permissionList != undefined && permissionList.length > 0) {
        for (let itemG of permissionList) {
            if (binding.value === itemG) {
                invalidFlag = true;
                break;
            }
        }
    }
    if (invalidFlag) {
        return;
    } else {
        el.parentNode.removeChild(el);
        return;
    }
}

export default hasPermission;